<template>
    <view class="mana">
        <view class="flex gs-item" v-if="options.level==0" @click="findRecord('leader')">
			<text>群主管理权转让</text>
			<view class="">
				<uni-icons size="24rpx" color="#999" type="right"></uni-icons> 
			</view>
		</view>
        <view class="flex gs-item" v-if="options.level==0" @click="findRecord('manage')">
			<text>群管理员</text>
			<view class="">
				<uni-icons size="24rpx" color="#999" type="right"></uni-icons> 
			</view>
		</view>
		<view class="flex gs-item">
			<text>全体禁言</text>
			<view class="">
				<switch color="#169BD5" :checked="checked" style="transform:scale(0.6)" @change="messageFree" />
			</view>
		</view>
		<view class="disband-group" @click="disbandGroup()">解散群聊</view>
    </view>
</template>
<script>
export default {
    data(){
        return {
			checked: false,
			options: {}
        }
    },
    onLoad(options){
		this.options = options
		this.checked = options.checked=='1'?true:false 
    },
    methods: {
        messageFree(e){
			let flag = e.detail.value
			this.api.post('chatGroupManage/muteAll', {
				chatGroupId: this.options.id,
				flag: flag
			}).then(res=>{
				if(res.data.state != 'ok') return;

			})
		},
        findRecord(type){
			uni.navigateTo({
				url: '/pages/group/all-members?id=' + this.options.id+'&type='+type
			})
		},
		disbandGroup(){
			this.utils.showModal('解散群组', '解散会移除所有群成员，并且无法再查看历史记录', delChatGroup)
			let that = this, id = this.options.id
			function delChatGroup(){
				that.api.post('chatGroupManage/delChatGroup', {
					chatGroupId: id
				}).then(res=>{
					if(res.data.state != 'ok') return;
					that.utils.showToast('解散成功')
						
					setTimeout(() => {
						let canNavBack = getCurrentPages()
						if(canNavBack && canNavBack.length > 1){
							uni.navigateBack({
								delta: 3
							})
						}else{
							history.go(-3);
						}
						
					}, 1000)
				})
			}
		},
		
    }
}
</script>
<style lang="less" scoped>
    .mana{
        padding: 32rpx;
		.flex{
			display: flex;
			justify-content: space-between;
			align-items: center;
			.uni-icons{
				margin-left: 8rpx;
			}
		}
        .gs-item{
			height: 80rpx;
		}
    }
	.disband-group{
		margin-top: 32rpx;
		color: #D9001B;
		font-size: 28rpx;
		text-align: center;
	}
</style>